package com.lqian.demo04;

public class ThreadLocalDemo {
    public static final ThreadLocal<Integer> local = new ThreadLocal<Integer>(){
        @Override
        protected Integer initialValue() {
            return 0;
        }
    };
    public static void main(String[] args) {
        Thread[] threads = new Thread[5];
        for (int i = 0; i <threads.length ; i++) {
            threads[i] = new Thread(()->{
                int num = local.get();
                num += 5;
                local.set(num);
                System.out.println(Thread.currentThread().getName()+"->num:"+num);
            },"Thread"+i);
        }
        for (Thread thread:threads) {
            thread.start();
        }
    }


}
